package com.zmn.oms.dubbo.impl.callcenter;

import com.alibaba.fastjson.JSON;
import com.zmn.base.common.data.common.dro.mobilecity.MobileCityDRO;
import com.zmn.base.common.data.dubbo.interfaces.mobilecity.MobilecityListRemoteService;
import com.zmn.common.dto2.ResponseDTO;
import com.zmn.common.utils.number.NumberUtil;
import com.zmn.common.utils.string.StringUtil;
import com.zmn.oms.business.interfaces.callinfo.CallInfoBService;
import com.zmn.oms.common.dto.ResultDTO;
import com.zmn.oms.dubbo.interfaces.callcenter.CallOrderRemoteService;
import com.zmn.oms.dubbo.utils.DubboConsts;
import com.zmn.oms.model.entity.callinfo.CallInfo;
import lombok.extern.slf4j.Slf4j;
import org.apache.dubbo.config.annotation.Reference;
import org.apache.dubbo.config.annotation.Service;
import org.springframework.beans.factory.annotation.Autowired;

/**
 * 类描述：呼叫录单
 * @author heciqi
 * @date 2020/8/13 11:03
 */
@Slf4j
@Service(loadbalance = "roundrobin", timeout = 10000, retries = 1, version = DubboConsts.INTERFACE_VERSION, validation = "true")
public class CallOrderRemoteServiceImpl implements CallOrderRemoteService {

	@Autowired
	private CallInfoBService callInfoBService;
	@Reference(version = com.zmn.base.plat.engine.common.constant.DubboConsts.INTERFACE_VERSION , check = false)
	private MobilecityListRemoteService mobilecityListRemoteService;

	@Override
	public ResponseDTO<Boolean> addOrder(String userPhone, Integer channelId, String remark) {
		log.info("营销专题录单入参userPhone:[{}],channelId:[{}]，remark[{}]", userPhone, channelId, remark);

		if (StringUtil.isBlank(userPhone) || NumberUtil.isNullOrZero(channelId)) {
			return ResponseDTO.fail("参入不正确");
		}

		CallInfo callInfo = new CallInfo();
		callInfo.setChannelId(channelId);
		callInfo.setUserPhone(userPhone);
		callInfo.setRemark(remark);
		callInfo.setCreater(userPhone);
		// 手机号码查询城市
		MobileCityDRO cityDRO = mobilecityListRemoteService.getByMobileNumberOrTelCode(userPhone).getData();
		if (cityDRO != null) {
			callInfo.setCityId(Integer.valueOf(cityDRO.getCityId()));
			callInfo.setCityName(cityDRO.getCityName());
		}

		log.info("callInfo=入参==>[{}]", callInfo);
		ResultDTO resultDTO = callInfoBService.insertCallInfo(callInfo);
		log.info("callInfo=出参==>[{}]", JSON.toJSONString(resultDTO));
		return resultDTO.isStatusBool() ? ResponseDTO.success(true) : ResponseDTO.fail(resultDTO.getMessage());
	}
}
